﻿#include <iostream>
#include <vector>
#include "newtonIP.h"
#include "functionrepos.h"
using namespace std;
int main()
{
	//v2,v4,v6,v8 is denoted n=2,n=4,n=6,n=8 respectively
	vector<double> v2 = { -5.0,0.0,5.0 };
	vector<double> v4 = { -5.0,-2.5,0.0,2.5,5.0 };
	vector<double> v6 = { -5.0,-10.0/3.0,-5.0/3.0,0.0,5.0/3.0,10.0/3.0,5.0 };
	vector<double> v8 = { -5.0,-3.75,-2.5,-1.25,0.0,1.25,2.5,3.75,5.0 };

	cout << "第二题演示:" << endl;
	for (int i = 0; i <= 100; i++)
	{
		double x = -5.0 + i * 0.1; //1 unit is divided 10 pieces
		cout << "原函数f的值：" << Bfunc(x) << "    2次：" << newtonIP(v2, Bfunc, x) << \
			"    4次：" << newtonIP(v4, Bfunc, x) << "    6次：" << newtonIP(v6, Bfunc, x) << \
			"    8次：" << newtonIP(v8, Bfunc, x) << endl;
	}
}
